package com.biz.primus.ms.commodity.trans;

import com.biz.primus.commodity.vo.backend.UpdateBrandVo;
import com.biz.primus.ms.commodity.dao.po.Brand;
import com.biz.primus.ms.commodity.dao.po.Category;
import com.google.common.base.Function;
import com.google.common.collect.Lists;
import javax.annotation.Nullable;

import java.util.List;


/**
 * @author 江南
 * @usage
 * @reviewer
 * @since 2016/12/22
 */
public class Brand2UpdateBrandVo implements Function<Brand, UpdateBrandVo> {
    @Nullable
    @Override
    public UpdateBrandVo apply(@Nullable Brand input) {
        UpdateBrandVo updateBrandVo = new UpdateBrandVo();
        updateBrandVo.setName(input.getName());
        updateBrandVo.setStatus(input.getStatus());
        List<Category> categories = input.getCategories();
        List<Long> categoryIds = Lists.newArrayList();
        for (Category category : categories) {
            categoryIds.add(category.getId());
        }
        updateBrandVo.setCategoryIds(categoryIds);
        updateBrandVo.setId(input.getId());
        updateBrandVo.setLogo(input.getLogo());
        updateBrandVo.setSaleChannel(input.getSaleChannel());
        updateBrandVo.setPrefix(input.getPrefix());
        return updateBrandVo;
    }
}
